package com.px.user.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import com.px.user.model.PagingModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.sql.Timestamp;

@Data
@SuperBuilder
@NoArgsConstructor
@Entity(name = "admin_ops")
@EqualsAndHashCode(callSuper = true)
@org.hibernate.annotations.Table(appliesTo = "admin_ops", comment = "管理员操作记录")
public class AdminOps extends PagingModel {

    @Id
    @ApiModelProperty(value = "主键")
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @ApiModelProperty(value = "用户ID", example = "1", hidden = true)
    @Column(columnDefinition = "bigint comment '用户ID'")
    private Long userId;

    @ApiModelProperty(value = "分类", example = "KICK_USER,BANED_USER", hidden = true)
    @Column(unique = true, columnDefinition = "varchar(256) comment '分类'")
    private String category;

    @ApiModelProperty(value = "角色: ADMIN,TEACHER,ROOMADMIN,CLIENT", example = "TEACHER", hidden = true)
    @Column(unique = true, columnDefinition = "varchar(256) comment '角色: ADMIN,TEACHER,ROOMADMIN,CLIENT'")
    private String role;

    @ApiModelProperty(value = "请求url", example = "@不提交")
    @Column(unique = true, columnDefinition = "varchar(512) comment '请求url'")
    private String url;

    @ApiModelProperty(value = "值")
    @Column(unique = true, columnDefinition = "varchar(1024) comment '值'")
    private String value;

    @ApiModelProperty(value = "备注")
    @Column(unique = true, columnDefinition = "varchar(1024) comment '备注'")
    private String remark;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;
}
